﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RaytracerLib.Layers;
using RaytracerLib.MathLib;
using TomanuExtensions;
using System.Diagnostics;

namespace RaytracerLib.Layers.Interpolators
{
    public class NearestNeighbourInterpolator : Interpolator
    {
        public NearestNeighbourInterpolator(ArrayBase a_array)
            : base(a_array)
        {
        }

        public override double InterpolateValue(double a_x, double a_y)
        {
            Debug.Assert(a_x >= 0);
            Debug.Assert(a_y >= 0);

            int x = (int)a_x;
            int y = (int)a_y;

            x = OverlayCorrector.CorrectX(x);
            y = OverlayCorrector.CorrectY(y);

            return m_array.GetValue(x, y);
        }

        public override ColorFloat InterpolateColor(double a_x, double a_y)
        {
            Debug.Assert(a_x >= 0);
            Debug.Assert(a_y >= 0);

            int x = (int)a_x;
            int y = (int)a_y;

            x = OverlayCorrector.CorrectX(x);
            y = OverlayCorrector.CorrectY(y);

            return m_array.GetColor(x, y);
        }
    }
}
